<?php
/**
 * DCRM Mobile Page
 *
 * This file is part of WEIPDCRM.
 * 
 * WEIPDCRM is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * WEIPDCRM is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 * 
 * You should have received a copy of the GNU Affero General Public License
 * along with WEIPDCRM.  If not, see <http://www.gnu.org/licenses/>.
 */

require_once('system/common.inc.php');
base_url();

// URL For Rewrite 
$rewrite_mod = get_option('rewrite_mod');
switch($rewrite_mod){
	case 3:
		$rewrite_url = array('view' => 'view/%d', 'view_nohistory' => 'view/%d/nohistory', 'screenshot' => 'screenshot/%d', 'history' => 'history/%d', 'contact' => 'contact/%d', 'section' => 'section/%d', 'report' => 'report/%d', 'report_support' => 'report/%1$d/%2$d', 'more' => 'more/%d', 'more_offset' => 'more/%1$d/%2$d', 'misc' => 'misc');
		break;
	case 1:
	case 2:
	default:
		$rewrite_url = array('view' => 'index.php?method=view&amp;pid=%d', 'view_nohistory' => 'index.php?pid=%d&amp;addr=nohistory', 'screenshot' => 'index.php?method=screenshot&amp;pid=%d', 'history' => 'index.php?method=history&amp;pid=%d', 'contact' => 'index.php?method=contact&amp;pid=%d', 'section' => 'index.php?method=section&amp;pid=%d', 'report' => 'index.php?method=report&amp;pid=%d', 'report_support' => 'index.php?method=report&amp;pid=%1$d&amp;support=%2$d', 'more' => 'index.php?method=more&amp;pid=%d', 'more_offset' => 'index.php?method=more&amp;pid=%1$d&amp;offset=%2$d', 'misc' => 'misc.php');
		break;
}
function echo_rewrite_url($type, $variable1, $variable2=''){
	global $rewrite_url;
	echo SITE_URL;
	printf($rewrite_url[$type], $variable1, $variable2);
}

class_loader('Mobile_Detect');
$detect = new Mobile_Detect;
if(!$detect->isiOS()){
	if (DCRM_PCINDEX == 2) {
		header("Location: ".SITE_URL.$rewrite_url['misc']);
		exit();
	} else {
		$isCydia = false;
	}
} else {
	if (DCRM_MOBILE == 2) {
		if (!strpos($detect->getUserAgent(), 'Cydia')) {
			$isCydia = false;
		} else {
			$isCydia = true;
		}
	} else {
		exit('Access Denied');
	}
}
if (file_exists('Release')) {
	$release = file('Release');
	$release_origin = __('No Name');
	$release_mtime = filemtime('Release');
	$release_time = date('Y-m-d H:i:s',$release_mtime);
	foreach ($release as $line) {
		if(preg_match('#^Origin#', $line)) {
			$release_origin = trim(preg_replace("#^(.+):\\s*(.+)#","$2", $line));
		}
		if(preg_match("#^Description#", $line)) {
			$release_description = trim(preg_replace("#^(.+):\\s*(.+)#","$2", $line));
		}
	}
} else {
	$release_origin = __('Empty Page');
}
if (isset($_GET['pid'])) {
	if (ctype_digit($_GET['pid']) && intval($_GET['pid']) <= 10000) {
		function device_check(){
			global $detect;
			$device_type = array('iPhone', 'iPod', 'iPad');
			for ($i = 0; $i < count($device_type); $i++) {
				$check = $detect->version($device_type[$i]);
				if ($check !== false) {
					if (isset($_SERVER['HTTP_X_MACHINE'])) {
						$DEVICE = $_SERVER['HTTP_X_MACHINE'];
					} else {
						$DEVICE = 'Unknown';
					}
					$OS = str_replace('_', '.', $check);
					break;
				}
			}
			return array('DEVICE' => $DEVICE, 'OS' => $OS);
		}

		if (isset($_GET['method']) && $_GET['method'] == 'screenshot') {
			$index = 2;
			$title = __('View Screenshots');
		} elseif (isset($_GET['method']) && $_GET['method'] == 'report') {
			$device_info = device_check();
			if (!isset($_GET['support'])) {
				$index = 3;
			} else {
				if ($_GET['support'] == '1') {
					$support = 1;
				} elseif ($_GET['support'] == '2') {
					$support = 2;
				} elseif ($_GET['support'] == '3') {
					$support = 3;
				} else {
					$support = 0;
				}
				$index = 4;
			}
			$title = __('Report Problems');
		} elseif (isset($_GET['method']) && $_GET['method'] == 'history') {
			$index = 5;
			$title = __('Version History');
		} elseif (isset($_GET['method']) && $_GET['method'] == 'contact') {
			$index = 6;
			$title = __('Contact us');
		} elseif (isset($_GET['method']) && $_GET['method'] == 'section') {
			$index = 7;
			$title = __('Package Category');
		} elseif (isset($_GET['method']) && $_GET['method'] == 'more') {
			$index = 8;
			$section = DB::fetch_first("SELECT `Name`, `Icon` FROM `".DCRM_CON_PREFIX."Sections` WHERE `ID` = '".(int)$_GET['pid']."'");
			$q_name = DB::real_escape_string($section['Name']);
			if (isset($_GET['offset']) && !empty($_GET['offset']) && ctype_digit($_GET['offset'])) {
				$offset = intval($_GET['offset']);
			} else {
				$offset = 0;
			}
			$packages = DB::fetch_all("SELECT `ID`, `Name`, `Package` FROM `".DCRM_CON_PREFIX."Packages` WHERE (`Stat` = '1' AND `Section` = '".$q_name."') ORDER BY `ID` DESC LIMIT 10 OFFSET ".$offset);
			foreach($packages as $package){
				if(!empty($package)){
					if ($isCydia) { ?>
				<a href="cydia://package/<?php echo($package['Package']); ?>" target="_blank">
<?php					} else { ?>
				<a href="<?php echo_rewrite_url('view', $package['ID']);?>">
<?php					} ?>
					<img class="icon" src="<?php echo(SITE_URL); ?>icon/<?php echo(empty($section['Icon']) ? 'default/unknown.png' : $section['Icon']); ?>">
					<div>
						<div>
							<label>
								<p><?php echo($package['Name']); ?></p>
							</label>
						</div>
					</div>
				</a>
<?php
				}
			}
			exit();
		} elseif (!isset($_GET['method']) || (isset($_GET['method']) && $_GET['method'] == 'view')) {
			$index = 1;
			$title = __('View Package');
			$package_id = (int)DB::real_escape_string($_GET['pid']);
			$package_info = DB::fetch_first("SELECT `Name`, `Version`, `Author`, `Package`, `Description`, `DownloadTimes`, `Multi`, `CreateStamp`, `Size`, `Installed-Size`, `Section`, `Homepage`, `Tag`, `Level`, `Price`, `Purchase_Link`, `Changelog`, `Changelog_Older_Shows`, `Video_Preview`, `System_Support`, `ScreenShots` FROM `".DCRM_CON_PREFIX."Packages` WHERE `ID` = '".$package_id."' LIMIT 1");
			if ($package_info) $title = $title.' - '.$package_info['Name'];
		} else {
			httpinfo(405);
			exit();
		}
	} else {
		httpinfo(405);
		exit();
	}
} elseif (!isset($_GET['method'])) {
	$index = 0;
	$title = $release_origin;
} else {
	httpinfo(405);
	exit();
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<title>最近7天更新的软件包</title>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
		<meta name="apple-mobile-web-app-title" content="<?php echo($release_origin); ?>" />
		<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
		<meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" />
		<meta name="HandheldFriendly" content="true" />
		<meta name="format-detection" content="telephone=no" />
		<meta name="robots" content="index, follow" />
<?php
if (defined("AUTOFILL_SEO")) {
?>
		<meta name="title" content="<?php echo(AUTOFILL_SEO); ?>" />
<?php
}
if (!empty($release_description)) {
?>
		<meta name="description" content="<?php echo($release_description); ?>" />
<?php
}
if (defined("AUTOFILL_KEYWORDS")) {
?>
		<meta name ="keywords" content="<?php echo(AUTOFILL_KEYWORDS); ?>" />
<?php
}
if ($isCydia) {
?>
		<base target="_blank">
<?php
} else {
?>
		<base target="_top">
<?php
}
?>
		<!--<base target="_top">--><base href="." target="_top">
		<link rel="apple-touch-icon" href="<?php echo(SITE_URL); ?>/fenlei/CydiaIcon.png">
		<link rel="shortcut icon" href="<?php echo(SITE_URL); ?>/favicon.ico">
		<link rel="stylesheet" href="<?php echo(SITE_URL); ?>/fenlei/menes.min.css">
		<link rel="stylesheet" href="<?php echo(SITE_URL); ?>/fenlei/scroll.min.css">
		<script src="<?php echo(SITE_URL); ?>/fenlei/push.js"></script><script src="./fenlei/fastclick.js" type="text/javascript"></script>
		<script src="<?php echo(SITE_URL); ?>/fenlei/menes.js" type="text/javascript"></script>
		<script src="<?php echo(SITE_URL); ?>/fenlei/cytyle.js" type="text/javascript"></script><!--<base target="_top">--><base href="." target="_top"><style type="text/css"> p, input[type="password"], input[type="text"], select { top: 0.051470588235294115em; } </style>
		<script src="<?php echo(SITE_URL); ?>/fenlei/jquery.min.js"></script>
	</head>
	<body class="pinstripe">
		<panel>
			
       
			<label><p></p><center>【最近7天更新的软件包】</center><p></p></label>

  <?php         
		if (DCRM_DIRECT_DOW2 == 2) {
?>

       <div class="box" style="height: 120px;">
					<ul>
						<li id="fuck5h" style="display: none;"><a href="<?php echo(AUTOFILL_Homelunbo); ?>" target="_blank" class=""><img id="fuck5hous" class="bigpic" src="<?php echo(SITE_URL); ?>/manage/Speed/icon/lunbo1.png"></a></li>					  
						<li id="fuck5h0" style="display: list-item;"><a href="<?php echo(AUTOFILL_Homelunbo2); ?>" target="_blank" class=" "><img class="bigpic" src="<?php echo(SITE_URL); ?>/manage/Speed/icon/lunbo2.png"></a></li>
					</ul>
				</div>
 <?php
		} 
?> 
          
<?php
	$down = DB::result_first("SELECT SUM(`DownloadTimes`)FROM `".DCRM_CON_PREFIX."Packages` WHERE `Stat` = '1'");
?>
 						<block class="box1" style="background-color:#3cb371;"><!--更多的软件包-->
					<p>全源下载总量：<?php printf( $down ); ?>次</p>
			</block>     
          	  <style>


/* reset webkit search input browser style */
input {
	outline: none;
}
input[type=search] {
	-webkit-appearance: textfield;
	-webkit-box-sizing: content-box;
	font-family: inherit;
	font-size: 100%;
}
input::-webkit-search-decoration,
input::-webkit-search-cancel-button {
	display: none; /* remove the search and cancel icon */
}

/* search input field */
input[type=search] {
	background: #ededed url(./Cydia/search-icon.png) no-repeat 9px center;
	border: solid 1px #ccc;
	padding: 9px 10px 9px 32px;
	width: 70%;
	
	-webkit-border-radius: 10em;
	-moz-border-radius: 10em;
	border-radius: 10em;
	
	-webkit-transition: all .5s;
	-moz-transition: all .5s;
	transition: all .5s;
}
input[type=search]:focus {
	width: 70%;
	background-color: #fff;
	border-color: #6dcff6;
	
	-webkit-box-shadow: 0 0 5px rgba(109,207,246,.5);
	-moz-box-shadow: 0 0 5px rgba(109,207,246,.5);
	box-shadow: 0 0 5px rgba(109,207,246,.5);
}

/* placeholder */
input:-moz-placeholder {
	color: #999;
}
input::-webkit-input-placeholder {
	color: #999;
}
button {
  -webkit-border-radius: 28;
  -moz-border-radius: 28;
  border-radius: 28px;
  text-shadow: 0px 1px 0px #2f6627;
  color: #ffffff;

  width: 15%;
  background: #44c767;

  border: solid #18ab29 1px;
  text-decoration: none;
}

button:hover {
  color: #ffffff;
  background: #5cbf2a;
  text-decoration: none;
}

</style>				
<?php
	if (!$isCydia) {
?>
<form action="http://mycydia.vip/mbsearch.php"  method="get" >
<center><span class="btn"><input type="search" name="name"  placeholder="在此输入您想要搜索安装的插件">
  <button type="submit" ><i></i>搜 索</button></span></center>
</form>
<?php
   }
?>
    
 <?php
              $packages = DB::fetch_all("SELECT `ID`, `Name`,`Icon2`, `Section`, `SectionID`,`CreateStamp`, `Description`,`DownloadTimes`,`Package` FROM `".DCRM_CON_PREFIX."Packages` WHERE (`Stat` = '1' AND (to_days(now())-to_days(CreateStamp))<=7) ORDER BY `CreateStamp` DESC ".$offset);

				foreach($packages as $package) {
					if ($isCydia) { ?>
           <fieldset id="section1" class="box">	
				<a href="cydia://package/<?php echo($package['Package']); ?>" target="_blank">
<?php				} else { ?>
           <fieldset id="section1" class="box">	
				<a href="<?php echo_rewrite_url('view', $package['ID']);?>">
<?php				} ?>
					<img class="icon" src="<?php echo(SITE_URL); ?>icon/<?php echo($package['Icon2']); ?>">
					<div>
						<div>
							<label>
								<p><?php echo($package['Name']); ?></p>  
							</label>
                        </div>
					</div>
				</a>
				<div>
				<p  style="text-align:left">◉更新时间：<?php echo($package['CreateStamp']); ?></p>
				</div>
                  </fieldset>
<?php
		} 
?>          

                  <p id="loadmore" name="1">
			</p>
			<label class="source">
				<p>软件源信息</p>
			</label>
			<fieldset class="source">
				<a href="http://mycydia.vip/">
					<img class="icon" src="./CydiaIcon.png">
					<div>
						<div>
							<label>
								<p id="source-name"><?php echo(AUTOFILL_SEO); ?></p>
							</label>
						</div>
					</div>
				</a>
				<div class="source-description" id="source-description">
					<p>个人分享源.自备份使用<br>所有插件.来自网络</p>
				</div>
			</fieldset>
			<script type="text/javascript">var siteurl = '//mycydia.vip/';</script>
		</panel>
		<script src="./fenlei/main1.js" type="text/javascript"></script>
		<div style="text-align: center; display: none;">
		</div>	
<script>
(function(){
    var bp = document.createElement('script');
    var curProtocol = window.location.protocol.split(':')[0];
    if (curProtocol === 'https') {
        bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
    }
    else {
        bp.src = 'http://push.zhanzhang.baidu.com/push.js';
    }
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(bp, s);
})();
</script>
</body></html>